package com.cc.openeye.dynamic.recommend.entity.dynamicResponse

import com.cc.openeye.dynamic.recommend.entity.LoadMoreStatus
import com.cc.openeye.dynamic.recommend.items.RecommendDynamicItemHelper
import com.tencent.kuikly.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
import kotlinx.serialization.Serializable

@Serializable
data class Item(
    val adIndex: Int,
    val `data`: Data? = null,
    val id: Int,
    val tag: String? = null,
    val trackingData: String? = null,
    val type: String,
    var loadingInfo: LoadingInfo? = null
) {
    fun getItemType() = if (type == RecommendDynamicItemHelper.ITEM_TYPE_PRE_LOAD_MORE) {
        RecommendDynamicItemHelper.ITEM_TYPE_PRE_LOAD_MORE
    } else if (type == RecommendDynamicItemHelper.ITEM_TYPE_LOAD_MORE) {
        RecommendDynamicItemHelper.ITEM_TYPE_LOAD_MORE
    } else {
        RecommendDynamicItemHelper.getItemType(type, data?.dataType ?: "")
    }

    fun getStaggeredGridItemSpan(): StaggeredGridItemSpan {
        val itemType = getItemType()
        return if (itemType == RecommendDynamicItemHelper.ITEM_TYPE_BANNER || itemType == RecommendDynamicItemHelper.ITEM_TYPE_SQUARE) {
            StaggeredGridItemSpan.FullLine
        } else {
            StaggeredGridItemSpan.SingleLane
        }
    }

    companion object {
        fun createPreLoadItem() =
            Item(0, id = 0, type = RecommendDynamicItemHelper.ITEM_TYPE_PRE_LOAD_MORE)

    }

}

@Serializable
data class LoadingInfo(var isNeedPreLoad: Boolean = false)
